added Feb 2001 SDK
[windows-sources.git] / shared source / wpf / src / host / shimimpl / persistfile.cxx
blob451a94312c94bd817a4b0b772e3ff29038786cc2
1 //+-----------------------------------------------------------------------
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 // Description:
6 // Defines the PersistFile class of PresentationHost
7 //
8 // History:
9 // 2002/06/12-murrayw
10 // Created
11 // 2007/09/20-[....]
12 // Ported Windows->DevDiv. See SourcesHistory.txt.
14 //------------------------------------------------------------------------
16 #include "Precompiled.hxx"
17 #include "PersistFile.hxx"
18 #include "HostShim.hxx"
19 #include "ShimUtilities.hxx"
21 //******************************************************************************
23 // CPersistFile::CPersistFile()
24 //
25 //******************************************************************************
27 CPersistFile::CPersistFile(__in CHostShim* pHostShim)
29 m_pHostShim = pHostShim;
32 //******************************************************************************
34 // CPersistFile::~CPersistFile()
35 //
36 //******************************************************************************
38 CPersistFile::~CPersistFile()
42 //******************************************************************************
44 // CPersistFile::QueryInterface()
46 //******************************************************************************
48 STDMETHODIMP CPersistFile::QueryInterface(REFIID riid, __out LPVOID *ppReturn)
50 return m_pHostShim->QueryInterface(riid, ppReturn);
53 //******************************************************************************
55 // CPersistFile::AddRef()
56 //
57 //******************************************************************************
59 STDMETHODIMP_(ULONG) CPersistFile::AddRef()
61 return m_pHostShim->AddRef();
64 //******************************************************************************
66 // CPersistFile::Release()
67 //
68 //******************************************************************************
70 STDMETHODIMP_(ULONG) CPersistFile::Release()
72 return m_pHostShim->Release();
75 //******************************************************************************
77 // CPersistFile::GetClassID()
78 //
79 //******************************************************************************
81 STDMETHODIMP CPersistFile::GetClassID(__out LPCLSID pClassID)
83 return m_pHostShim->GetClassID(pClassID);
86 //******************************************************************************
88 // CPersistFile::Save()
89 //
90 //******************************************************************************
92 STDMETHODIMP CPersistFile::Save(__in_ecount(MAX_PATH+1) LPCOLESTR, BOOL)
94 // File->Save is enabled/disabled by IOleCommandTarget->QueryStatus like any other menu item
95 // However, once enabled it calls IPersistFile->Save rather than IOleCommandtarget->Exec.
96 // To make it work like the other menu items we simply turn around and call Exec ourselves.
97 HRESULT hr = S_OK;
98 IOleCommandTarget* pCmdTarget = NULL;
99 CKHR(QueryInterface(IID_IOleCommandTarget, (VOID**)&pCmdTarget));
100 CKHR(pCmdTarget->Exec(NULL, OLECMDID_SAVE, NULL, NULL, NULL));
102 Cleanup:
103 ReleaseInterface(pCmdTarget);
104 return hr;
107 //******************************************************************************
109 // CPersistFile::SaveCompleted()
111 //******************************************************************************
113 STDMETHODIMP CPersistFile::SaveCompleted(LPCOLESTR pwszFile)
115 return E_NOTIMPL;
118 //******************************************************************************
120 // CPersistFile::Load()
122 // This method is called if file is local.
124 //******************************************************************************
126 STDMETHODIMP CPersistFile::Load(__in_ecount(MAX_PATH + 1) LPCOLESTR pwszFile, DWORD dwMode)
128 HRESULT hr = S_OK;
129 CString strMimeType;
130 MimeType mimeType = MimeType_Unknown;
132 EventWriteWpfHostUm_IPersistFileLoad(pwszFile);
134 m_pHostShim->SetActivationType(FileActivation);
136 if (m_pHostShim->GetAllowPersistFileLoad() == FALSE && m_pHostShim->IsAllowPersistFileLoadSet())
138 return E_FAIL;
141 CK_PARG(pwszFile);
142 if (!*pwszFile)
143 return E_INVALIDARG;
145 m_pHostShim->SetStartupUri(pwszFile);
146 m_pHostShim->SetLocalDeploymentManifestPath(pwszFile);
148 const DWORD SZMIMESIZE_MAX = 128;
149 WCHAR wzBuffer[SZMIMESIZE_MAX + 1];
150 DWORD dwCharCount = SZMIMESIZE_MAX;
152 CKHR(AssocQueryString(
153 0, // ASSOCF flags,
154 ASSOCSTR_CONTENTTYPE, // ASSOCSTR str,
155 PathFindExtension(pwszFile), // LPCTSTR pszAssoc,
156 0, // LPCTSTR pszExtra,
157 wzBuffer, // LPTSTR pszOut,
158 &dwCharCount // DWORD *pcchOut
161 mimeType = GetMimeTypeFromString(wzBuffer);
163 m_pHostShim->SetMimeType(mimeType);
165 // error out if we don't have an application or container
166 if (!IsValidMimeType(mimeType))
168 CKHR(E_FAIL);
171 // Note: Execute() triggers Watson on any failure.
172 m_pHostShim->Execute();
173 hr = S_OK;
175 Cleanup:
176 return hr;
179 //******************************************************************************
181 // CPersistFile::IsDirty()
183 //******************************************************************************
185 STDMETHODIMP CPersistFile::IsDirty()
187 return S_FALSE;
190 //******************************************************************************
192 // CPersistFile::GetCurFile()
194 //******************************************************************************
196 STDMETHODIMP CPersistFile::GetCurFile(__out LPOLESTR *ppwszOut)
198 return E_NOTIMPL;